<?php

namespace app\common\model\mysql;

use think\Model;

class OrderTask extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'or_order_task';

    /**
     * 查询订单任务数据列表
     * @param array $where
     * @param string $field
     * @return OrderProductWater[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNormalOrderTask(array $where = [], string $field = "*"){
        $order = [
            "order_task_id" =>"asc",
        ];
        $result = $this->where($where)->field($field)->order($order)->select();
        return $result->toArray();
    }

    /**
     * 获取订单任务单个字段数组
     * @param $where
     * @param $field
     * @return array
     */
    public function getNormalOrderTaskFiledArr($where, $field){
        $order = [
            "order_task_id" =>"asc",
        ];
        $result = $this->where($where)->order($order)->column($field);
        return $result;
    }

    /**
     * 根据主键id更新数据表中的数据
     * @param $id
     * @param $data
     * @return bool
     */
    public function saveOrderTaskData($id,$data){
        $id = intval($id);
        if(empty($id) || empty($data) || !is_array($data)){
            return false;
        }
        $where = [
            "order_task_id"=>$id,
        ];
        return $this->where($where)->save($data);
    }

    /**
     * 查询订单任务金钱总量
     * @param array $where
     * @param string $field
     * @return float
     */
    public function getNormalOrderTaskSum(array $where = [], string $field = "sellcount"){
        $result = $this->where($where)->sum($field);
        return $result;
    }
}
